package com.avic.rong.course.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.avic.rong.R;
import com.avic.rong.course.bean.PeiXunJiangShiBean;
import com.bumptech.glide.Glide;

import java.util.ArrayList;

/**
 * Created by Chenjiaxin on 2019/8/18 10:31
 * E-Mail Address：16601203965@163.com
 */
public class AuthorIntroductionRvAdapter extends RecyclerView.Adapter<AuthorIntroductionRvAdapter.BgRvViewHolder>{

    private Context context;
    private ArrayList<PeiXunJiangShiBean> list;
    private LayoutInflater inflater;

    public AuthorIntroductionRvAdapter(Context context, ArrayList<PeiXunJiangShiBean> list) {
        this.context = context;
        this.list = list;
        this.inflater = LayoutInflater.from(context);
    }

    @NonNull
    @Override
    public BgRvViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = inflater.inflate(R.layout.view_author_introduction_item, viewGroup, false);
        return new BgRvViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull BgRvViewHolder holder, int i) {
        Glide.with(context).load(""+list.get(i).getPortrait()).placeholder(R.mipmap.ic_default_head).into(holder.img);
        holder.name.setText(list.get(i).getName());
        holder.text.setText(list.get(i).getIntroduce());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class BgRvViewHolder extends RecyclerView.ViewHolder{
        ImageView img;
        TextView text,name;
        public BgRvViewHolder(@NonNull View itemView) {
            super(itemView);
            img = itemView.findViewById(R.id.author_img);
            name = itemView.findViewById(R.id.author_name);
            text = itemView.findViewById(R.id.author_text);
        }
    }
}
